HERE提供多種RESTFul API的接口,如下述幾項常見的地理資訊運用API:
更多細項,可參考網站:https://developer.here.com/documentation#maps_section
首先要使用這些API,您必須於HERE Developer( https://developer.here.com/ ),註冊HERE的開發者帳戶,目前HERE提供可註冊Freemium的開發者帳戶,簡易且快速的讓開發者每月能免費使用250K的傳輸計量。
當然如果您需要更好且更多傳輸量的服務,也可選擇付費的方案,細節請參考: https://developer.here.com/pricing。
完成後,即可立即開始使用HERE的RESTFul API,mobile SDK或JavaScript的不同服務,此篇文章主要針對RESTFul API的憑證獲取說明。
進入所屬的Project,選擇REST-> Generate APP,系統將立刻創建一組您專屬的APP ID。
完成後,您可看到兩種獲取憑證的方式API KEY 或 OAuth 2.0,在此篇文章將分別介紹,兩種認證的差異與使用方式。
這個方式是最快速且簡單獲取憑證的方式,您可以點選Creater API KEY
後,系統於1分鐘內將產生一串代碼,而開發者則可立即使用這組代碼,去調用HERE的RESTFul API。
使用API KEY用戶可以隨時刪除新增一組新的API KEY,彈性的增加了安全性與避免被盜用的情況。而一個API ID最多能產生兩組的API KEY。
例如,API KEY使用於PLACE API的方式與結果:
https://places.ls.hereapi.com/places/v1/discover/search?q=夜市&threshold=true&Accept-Language=zh-TW&apikey=[YourApikey]&addressFilter=countryCode=TWN&at=25.039920,121.512919&size=1
{
"results":{
"next": "https://places.ls.hereapi.com/places/v1/discover/search;context=Zmxvdy1pZD1iMWU4NjYwNS1lNDk2LTVjY2EtOTU5NC03ODFlNzU4NmZkNWJfMTYwMDE0MDg1MTUwMF8xOTQxXzQzMDgmb2Zmc2V0PTEmc2l6ZT0xJmNzPXBsYWNlcyUyQ2N1aXNpbmVzJTJDcGRz?at=25.03992%2C121.512919&q=%E5%A4%9C%E5%B8%82&app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"items":[
{
"position":[
25.05616,
121.51533
],
"distance": 1822,
"title": "寧夏夜市",
"averageRating": 0.0,
"categories":[
{
"id": "sights-museums",
"title": "景點與博物館",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/sights-museums?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "places",
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/10.icon"
},
{
"id": "shop",
"title": "商店",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/shop?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "places",
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/09.icon"
},
{
"id": "landmark-attraction",
"title": "地標/景點",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/landmark-attraction?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "places",
"icon": "https://download.vcdn.data.here.com/p/d/places2/icons/categories/38.icon"
},
{
"id": "300-3000-0023",
"title": "旅遊景點",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/300-3000-0023?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "pds"
},
{
"id": "600-6900-0103",
"title": "禮品、古董與藝品",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/600-6900-0103?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "pds"
},
{
"id": "600-6900-0247",
"title": "市場",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/600-6900-0247?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "pds"
},
{
"id": "600-6900-0000",
"title": "日常必需品",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/600-6900-0000?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "pds"
},
{
"id": "300-3000-0000",
"title": "地標或熱門地點",
"href": "https://places.ls.hereapi.com/places/v1/categories/places/300-3000-0000?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"type": "urn:nlp-types:category",
"system": "pds"
}
],
"vicinity": "台北市大同區寧夏路",
"having":[],
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/158wsqqt-1b3cb3b5b9394824970a9e3947dff02a;context=Zmxvdy1pZD1iMWU4NjYwNS1lNDk2LTVjY2EtOTU5NC03ODFlNzU4NmZkNWJfMTYwMDE0MDg1MTUwMF8xOTQxXzQzMDgmcmFuaz0wJmNzPXBsYWNlcyUyQ2N1aXNpbmVzJTJDcGRz?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA",
"id": "158wsqqt-1b3cb3b5b9394824970a9e3947dff02a",
"alternativeNames":[
{
"name": "Ningxia Night Market",
"language": "en"
}
]
}
]
},
"search":{
"context":{
"location":{
"position":[
25.03992,
121.512919
],
"address":{
"text": "台灣台北市中正區重慶南路一段122號",
"house": "122",
"street": "重慶南路一段",
"postalCode": "100",
"district": "中正區",
"city": "台北市",
"county": "台北市",
"country": "台灣",
"countryCode": "TWN"
}
},
"type": "urn:nlp-types:place",
"href": "https://places.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPSVFNSU4RiVCMCVFNSU4QyU5NyVFNSVCOCU4MiVFNCVCOCVBRCVFNiVBRCVBMyVFNSU4RCU4MCVFOSU4NyU4RCVFNiU4NSVCNiVFNSU4RCU5NyVFOCVCNyVBRiVFNCVCOCU4MCVFNiVBRSVCNTEyMiVFOCU5OSU5RjtsYXQ9MjUuMDM5OTI7bG9uPTEyMS41MTI5MTk7c3RyZWV0PSVFOSU4NyU4RCVFNiU4NSVCNiVFNSU4RCU5NyVFOCVCNyVBRiVFNCVCOCU4MCVFNiVBRSVCNTtob3VzZT0xMjI7Y2l0eT0lRTUlOEYlQjAlRTUlOEMlOTclRTUlQjglODI7cG9zdGFsQ29kZT0xMDA7Y291bnRyeT1UV047ZGlzdHJpY3Q9JUU0JUI4JUFEJUU2JUFEJUEzJUU1JThEJTgwO2NvdW50eT0lRTUlOEYlQjAlRTUlOEMlOTclRTUlQjglODI7Y2F0ZWdvcnlJZD1idWlsZGluZztzb3VyY2VTeXN0ZW09aW50ZXJuYWw;context=c2VhcmNoQ29udGV4dD0x?app_id=xwblj8gfwvaYrFirbs0l&app_code=hf36DfGnoIdrcgvwGH0IdA"
},
"ranking": "default"
}
}
點選Creater Crendientials
後,系統於1分鐘內將產生一組憑證,這組憑證將用於之後獲取Token的憑鑰。
OAuth 2.0 為業界使用Bearer Access Tokens的標準協議方式,主要概念為從HERE網站獲取Access Key 與 Access Key Secret,透過OAuth API回傳一組Token,利用這組Token去呼叫HERE API服務,而取代使用API KEY。
您可能覺得為何需要多此一舉,主要的原因,是透過這個方式產生的Token只會有24小時的效力,過了24小時候,開發者必須重新呼叫OAuth API傳回另一組Token以供未來24小時使用。
這樣的方法,提高了開發者使用API的安全性,但開發者也必須多撰寫程序,將整個獲取憑證的過程編成自動化的過程。
此篇,利用Postman(https://www.getpostman.com/downloads/)工具呈現這個過程,
Type
為“OAuth 1.0”,確定Add authorization data to
為“Request Headers”,於Consumer Key
鍵入HERE開發者網站中獲取的Access Key,於Consumer Secre
鍵入HERE開發者網站中獲取的Access Key Secretx-www-form-urlencoded
,並增加 Key “grant_type” 定義其質為 client_credentials
.SEND
後,於回傳的內容即可發現回傳Access_Token
,這組access token即可在未來的24小時內調用HERE RestFul API。例如,access_token於PLACE API的方式與結果:
Bearer Token
,並輸入獲取的Access_Token
。